package indi.zhifa.engine.starter.web;

import indi.zhifa.engine.core.common.enums.controller.EnumApi;
import indi.zhifa.engine.core.common.enums.properties.EnumMemoProperties;
import indi.zhifa.engine.core.common.enums.service.IEnumMemoService;
import indi.zhifa.engine.core.common.enums.service.impl.EnumMemoServiceImpl;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "zhifa.enum-memo",name = "enabled", havingValue = "true")
public class EnumCommonStarterConfig {
    @Bean
    @ConfigurationProperties(prefix = "zhifa.enum-memo")
    public EnumMemoProperties enumMemoProperties() {
        EnumMemoProperties enumMemoProperties = new EnumMemoProperties();
        return enumMemoProperties;
    }

    @Bean
    public IEnumMemoService enumMemoService(EnumMemoProperties pEnumMemoProperties){
        EnumMemoServiceImpl enumMemoService = new EnumMemoServiceImpl(pEnumMemoProperties);
        return enumMemoService;
    }

    @ConditionalOnMissingBean
    @Bean
    public EnumApi enumApi(IEnumMemoService pEnumMemoService){
        EnumApi enumApi = new EnumApi(pEnumMemoService);
        return enumApi;
    }
}
